import dayjs from '../../../utils/dayjs.min'
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    dataTypeTxt: '请选择',
    dateTypeOption: [{
        text: '年份',
        value: 0
      },
      {
        text: '季度',
        value: 1
      },
      {
        text: '月份',
        value: 2
      },
    ],
    selectedOption: [],
    dateType: '',
    selectedValue: '',
    selectedTxt: '请选择',
    yearColumns: (() => {
      let arrs = []
      let year = new Date().getFullYear();
      for (let i = 0; i < 10; i++) {
        arrs.push({
          text: (year - i) + '年',
          value: year - i
        })
      }
      return arrs
    })(),
    quarterColumns: [{
        text: '第一季度',
        value: '1'
      },
      {
        text: '第二季度',
        value: '2'
      },
      {
        text: '第三季度',
        value: '3'
      },
      {
        text: '第四季度',
        value: '4'
      },
    ],
    monthColumns: (() => {
      let arrs = []
      for (let i = 1; i < 13; i++) {
        arrs.push({
          text: i + '月',
          value: i < 10 ? '0' + i : i
        })
      }
      return arrs
    })(),
  },
  created() {},
  /**
   * 组件的方法列表
   */
  methods: {
    dateTypeChange(e) {
      this.setData({
        dateType: e.detail
      })
      if (e.detail == 0) {
        this.setData({
          selectedOption: this.data.yearColumns,
          dataTypeTxt: '年份'
        })
      } else if (e.detail == 1) {
        this.setData({
          selectedOption: this.data.quarterColumns,
          dataTypeTxt: '季度'
        })
      } else if (e.detail == 2) {
        this.setData({
          selectedOption: this.data.monthColumns,
          dataTypeTxt: '月份'
        })
      }
    },
    valueChange(e) {
      let txt = '';
      let params = {
        year: '',
        quarter: '',
        month: '',
      }
      if (this.data.dateType == 0) {
        txt = this.data.yearColumns.filter(item => item.value == e.detail)[0].text
        params.year = e.detail
      } else if (this.data.dateType == 1) {
        txt = this.data.quarterColumns.filter(item => item.value == e.detail)[0].text
        params.quarter = e.detail
      } else if (this.data.dateType == 2) {
        txt = this.data.monthColumns.filter(item => item.value == e.detail)[0].text
        params.month = e.detail
      }
      this.setData({
        selectedValue: e.detail,
        selectedTxt: txt
      })
      this.triggerEvent('change', params)
    },
    clear() {
      this.setData({
        selectedTxt: '请选择',
        dataTypeTxt: '请选择',
        selectedValue: '',
        dateType: ''
      })
    }
  }
})